package com.qf.cosmetology.controller;

import com.qf.cosmetology.entity.Subject;
import com.qf.cosmetology.result.ResponseCode;
import com.qf.cosmetology.result.ResponseData;
import com.qf.cosmetology.service.SubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.omg.PortableInterceptor.SUCCESSFUL;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Subject)表控制层
 *
 * @author makejava
 * @since 2021-06-25 16:54:07
 */
@Api("SubjectApi")
@RestController
@RequestMapping("subjects")
public class SubjectController {
    /**
     * 服务对象
     */
    @Resource
    private SubjectService subjectService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    public ResponseData selectOne(@PathVariable Integer id) {
        Subject subject = subjectService.queryById(id);
        System.out.println("controller");
        return new ResponseData(ResponseCode.SUCCESS,subject);
    }

//    @ApiOperation(value = "queryByPriceDesc",notes = "查询数据库10条数据")
//   //@ApiImplicitParam(name = "",value = "查询十条数据")
//    @GetMapping("/v1/")
//    public List<Subject> queryByPriceDesc(){
//        System.out.println("hahahhah");
//        return this.subjectService.queryByPriceDesc();
//
//    }
    @GetMapping("/{shi}/{li}")
    public ResponseData queryAllByLimit(@PathVariable Integer shi, @PathVariable Integer li) {
        List<Subject> subjects = subjectService.queryAllByLimit(shi, li);
        System.out.println("长=" + subjects.size());
        return new ResponseData(ResponseCode.SUCCESS, subjects);
    }

    @ApiOperation(value = "queryByPriceDesc",notes = "查询数据库10条数据")
    @ApiImplicitParam(name = "",value = "查询十条数据")
    @GetMapping("/")
    public ResponseData queryByPriceDesc() {
        List<Subject> subjects = subjectService.queryByPriceDesc();
        System.out.println("Controller" + subjects.size());
        return new ResponseData(ResponseCode.SUCCESS, subjects);
    }

    @ApiOperation(value = "queryByTitle",notes = "根据标题找列表")
    @ApiImplicitParam(name = "title",value = "根据标题找列表")
    @GetMapping("/v1/{title}")
    public ResponseData queryByTitle(@PathVariable String title) {
        List<Subject> subjects = subjectService.queryByTitle(title);
        System.out.println("Controller" + subjects.size());
        return new ResponseData(ResponseCode.SUCCESS, subjects);
    }





}
